<template>
    <div class="bg-content">
        <div class="title">
            <img src="@/assets/home/cricle.png" alt="" class="title-pl" />
            <span class="s-title">
                <span class="title-name">&nbsp;&nbsp;总充电量</span>
            </span>
            <span class="fl">
                <span class="f-active">市充电量</span>&nbsp;|&nbsp;
                <span>储能售电量</span>
            </span>
<!--            <span class="right-light">-->
<!--                <span class="active">日</span>&nbsp;&nbsp;-->
<!--                <span>月</span>-->
<!--                <span>年</span>-->
<!--            </span>-->
          <span class="right-light">
          <span
              :class="{ active: timeUnit === 'day' }"
              @click="setTimeUnit('day')">日</span>&nbsp;&nbsp;
          <span
              :class="{ active: timeUnit === 'month' }"
              @click="setTimeUnit('month')">月</span>&nbsp;&nbsp;
          <span
              :class="{ active: timeUnit === 'year' }"
              @click="setTimeUnit('year')">年</span>
          </span>
        </div>
        <div class="content">
            <div>
                <div class="sun">
                    <div><img src="@/assets/home/one.png" alt=""></div>
                    <div class="pl">
                        <div>光伏售电量</div>
                        <div>{{ pvSelling }}</div>
                    </div>
                </div>
                <div class="sun">
                    <div><img src="@/assets/home/two.png" alt=""></div>
                    <div class="pl">
                        <div>市充电量</div>
                        <div>{{ normalSelling }}</div>
                    </div>
                </div>
            </div>
            <div class="center-sun">
                <div>总充电量</div>
                <div>{{ Totalselling }}</div>
            </div>
            <div>
                <div class="sun">
                    <div><img src="@/assets/home/three.png" alt=""></div>
                    <div class="pl">
                        <div>光伏售电占比</div>
                        <div>{{ pv_ratio_percentage }}</div>
                    </div>
                </div>
                <div class="sun">
                    <div><img src="@/assets/home/four.png" alt=""></div>
                    <div class="pl">
                        <div>市充电占比</div>
                        <div>{{ normal_ratio_percentage }}</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import axios from "axios";

export default {
  props: {
    regionId: {
      type: String,
      default: '100000',
    },
  },
  watch: {
    regionId(newVal) {
      //console.log("新的区域IDnnnnnnnnnnnnnnnnnn:", newVal);
      // 在这里可以根据新的区域ID重新请求数据或更新图表
      this.getregionId(newVal);
    },
    timeUnit(newVal){
      this.timeUnit()
    }
  },
    data() {
        return {
          timeUnit: 'year', // 默认选中“日”
          pvSelling: 0,
          normalSelling: 0,
          normal_ratio_percentage: "0%",
          pv_ratio_percentage: "0%",
          Totalselling: 0,
          date: 1 // 默认日期
        };
    },
    methods: {
      setTimeUnit(unit) {
        this.timeUnit = unit; // 更新当前时间单位
        // 这里可以添加其他逻辑，例如请求数据等
        // 根据选择的时间单位设置 date 的值
        if (unit === 'year') {
          this.date = 1; //
        } else if (unit === 'month') {
          this.date = 2; //
        } else if (unit === 'day') {
          this.date = 3; //
        }
        this.getregionId(); // 更新数据
      },
    getregionId(){
      const regionId = this.regionId; // 获取当前的 regionId
      const two_four = 3;
      const date = this.date;
      axios.get(`${this.$httpUrl}charge?two_four=${two_four}&date=${date}&id=${regionId}`)
          .then(response => {
            const dataFromApi = response.data; // 从响应中获取数据
            this.pvSelling = dataFromApi.pvSelling;
            this.normalSelling = dataFromApi.normalSelling;
            this.normal_ratio_percentage = dataFromApi.normal_ratio_percentage;
            this.pv_ratio_percentage = dataFromApi.pv_ratio_percentage;
            this.Totalselling = dataFromApi.Totalselling;

            this.init(); // 在获取数据后初始化图表
          })
          .catch(error => {
            console.error("获取数据失败:", error);
          });
      console.log("E7777777777777777777:",regionId)
    }
    },
  mounted() {

    this.getregionId();
  }
};
</script>

<style lang="less" scoped>
.bg-content {
    height: calc((100vh - 0.75rem) / 3 - 0.18rem);
    margin-bottom: 0.05rem;
    position: relative;
    border-width: 1px;
    border-style: solid;
    border-image: linear-gradient(to right, #44c9c9,#000606) 1;
    padding: 0.05rem;
    .title {
        color: #ffffff;
        position: relative;
        height: 0.35rem;
        line-height: 0.35rem;
        text-align: left;
        border-bottom: 3px solid transparent;
        border-image: linear-gradient(to right, #3aacac, #000202) 1;
        .title-name {
            font-size: 0.14rem;
            font-weight: bold;
        }
        .title-pl {
            position: relative;
            top: 0.05rem;
        }
        .right-light {
            position: absolute;
            right: 0;
            display: inline-block;
            font-size: 0.14rem;
            padding: 0;
            height: 0;
            font-weight: 400;
            span {
                padding: 2px 5px;
                background-color: #091a1a;
                cursor: pointer;
            }
        }
        .active {
            background-image: url("./../../../assets/home/sun.png");
        }
        .fl{
            font-size: 13px;
            color: gray;
            font-weight: bold;
            margin-left: 0.5rem;
        }
        .f-active{
            color: #4ee7e7;
        }
    }
    .content{
        height: calc((100vh - 0.75rem) / 3 - 0.18rem - 0.45rem );
        background: url('./../../../assets/home/left-center-bg.png');
        background-size: 100% 100%;
        margin: 0.1rem;
        display: flex;
        >div{
            flex:1
        }
        .center-sun{
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            >div:nth-child(1){
                font-size: 13px;
                font-weight: bold;
                color: #ffffff;
            }
            >div:nth-child(2){
                font-size: 20px;
                font-weight: bold;
                background: linear-gradient(to bottom, #ffffff, #56fefe); /* 渐变颜色 */
                -webkit-background-clip: text; /* 仅应用背景到文本 */
                -webkit-text-fill-color: transparent; /* 使文本填充透明 */
                text-fill-color: transparent; /* 对于非WebKit浏览器 */
            }
        }
        .sun{
            display: flex;
            color: #ffffff;
            height: 50%;
            justify-content: center;
            align-items: center;
            img{
                margin-right: 5px;
            }
            .pl{
                >div:nth-child(1){
                    font-size: 12px;
                }
                >div:nth-child(2){
                    font-size: 20px;
                    font-weight: bold;
                }
            }
        }
    }
}
</style>
